home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-05-03 | 2.4 KB | 89 lines | [TEXT/PJMM] |
- program GRAFCollisions;
-
- uses
- graphics;
-
- var
- aa, ab: rect;{aa=the entire cicn size, ab=the size to use when testing for collisions}
- rocket1, rocket2: Face;
- explosion: array[0..2] of Face;
- temp: integer;
- l: longint;
- explosionhappened: boolean;
- delay: integer;
-
- procedure setupleftrocket (var me: sprite);
- begin
- me.speed.h := 3;
- end;
-
- procedure setuprightrocket (var me: sprite);
- begin
- me.speed.h := -3;
- end;
-
- procedure dorockettask (var me: sprite);
- begin
- me.position.h := me.position.h + me.speed.h;
- end;
-
- procedure setupexplosion (var me: sprite);
- begin
- me.mode := 0;
- explosionhappened := true;
- end;
-
- procedure doexplosiontask (var me: sprite);
- begin
- me.mode := (me.mode + 1) mod 3; {this is where we rotate through the faces for the explosion.}
- me.theface := explosion[me.mode];
- if me.mode = 0 then
- killsprite(me); {when done exploding, we eliminate the explosion sprite}
- end;
-
- procedure dorockethit (var me: sprite; var him: sprite);
- var
- a, b, c: integer;
- begin
- if me.position.h > him.position.h then {we don't know if the left rocket or the right rocket will trigger a collision}
- b := him.position.h + 16; {so we put in code for both. Whichever rocket is further left, we calculate}
- if him.position.h > me.position.h then {the starting position for the explosion from it}
- b := me.position.h + 16;
- c := me.position.v - 6;
- killsprite(me);
- killsprite(him);
- a := NewSprite(3, b, c, 0, explosion[0], @doexplosiontask, nil, @setupexplosion);
- playsound(true);
- end;
-
- procedure setupsprite;
- begin
- setrect(aa, 0, 0, 32, 19);
- setrect(ab, 0, 0, 32, 19);
- rocket1 := newface(128, aa, ab);
- rocket2 := newface(129, aa, ab);
- setrect(aa, 0, 0, 32, 32);
- setrect(ab, 0, 0, 32, 32);
- explosion[0] := newface(130, aa, ab);
- explosion[1] := newface(131, aa, ab);
- explosion[2] := newface(132, aa, ab);
- getsound(128);
- temp := NewSprite(1, 100, 200, 0, rocket1, @dorockettask, @dorockethit, @setupleftrocket);
- temp := NewSprite(2, 400, 200, 0, rocket2, @dorockettask, @dorockethit, @setuprightrocket);
- explosionhappened := false;
- delay := 4;
- end;
-
- begin
- GRAFInit(128, 512, 342);
- setcollisionhandling(2);
- setupsprite;
- repeat
- l := tickcount;
- RunGRAF(2);
- if explosionhappened = true then
- delay := 12; {when a collision happens, we increase the delay so you can see the explosion better}
- while l > tickcount - delay do
- ;
- until button;
- end.